// const dayjs = require("dayjs");
// import { changeDate } from '../../api/test/index'
import { getNewPersonalChannelList, getNewNewCarClueList } from '../../api/index/index'
import config from '../../config/index';
import { getToken } from '../../utils/storage';
Page({
  data: {
    bannerList: [
      {id: 1, img: 'https://wm.foskeli.com/uploads/1.jpg'},
      {id: 2, img: 'https://wm.foskeli.com/uploads/2.jpg'},
      {id: 3, img: 'https://wm.foskeli.com/uploads/3.jpg'}
    ],
    newPersonalChannelList: [] as ListPersonalChannel[] | ListPersonalChannel[][],
    newNewCarClueList: [] as ListNewCarClue[] | ListNewCarClue[][]
  },
  
  onShow() {
    this.checkLogin()
    this.initList()
    if (typeof this.getTabBar === 'function' &&
        this.getTabBar()) {
        this.getTabBar().setData({
          selected: 0
        })
      }
  },
  //判断是否登录
  checkLogin() {
    if(!getToken()) {
      wx.showToast({
        title: '未登录',
        icon: 'error',
        success: () => {
          setTimeout(() => {
            wx.navigateTo({
              url: '/pages/login/login'
            })
          }, 1000)
        }
      })
    }
  },
  async initList() {
    const channelRes = await getNewPersonalChannelList()
    const clueRes = await getNewNewCarClueList()
    if(channelRes.statusCode === config.SUCCESS_CODE) {
      this.setData({
        newPersonalChannelList: channelRes.data
      })
    }
    if(clueRes.statusCode === config.SUCCESS_CODE) {
      this.setData({
        newNewCarClueList: clueRes.data
      })
    }
  },
  toPersonalChannel() {
    wx.navigateTo({
      url: '/pages/personalChannel/personalChannel'
    })
  },
  toNewCarClue() {
    wx.navigateTo({
      url: '/pages/newCarClue/newCarClue'
    })
  },
  toChannelDetail(e: any) {
    let id: number = e.currentTarget.dataset.channelid
    wx.navigateTo({
      url: `/pages/personalChannelDetail/personalChannelDetail?id=${id}`
    })
  },
  toClueDetail(e: any) {
    let id: number = e.currentTarget.dataset.clueid
    wx.navigateTo({
      url: `/pages/newCarClueDetail/newCarClueDetail?id=${id}`
    })
  }
})
